#!/bin/sh

# Slackware build script for bloodcm

# Written by B. Watson (yalhcru@gmail.com)

# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.

# Just repacks the data, no compiling or executables.
# No icon or .desktop, because no executables.

PRGNAM=bloodcm
VERSION=${VERSION:-12.2016}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}

ARCH=noarch

CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

set -e

# depending on what the file was downloaded with, it'll be named
# either of these:
ZIPFILE="38-blood-crossmatching"
[ -e $CWD/$ZIPFILE ] || ZIPFILE="${PRGNAM}_v${VERSION}.zip"
[ -e $CWD/$ZIPFILE ] || ZIPFILE="${PRGNAM}_${VERSION}.zip"

# directory inside the zipfile containing the stuff we want. the
# rest is binaries for windows.
DIRNAME="BloodCM"

# this needs to match eduke32.SlackBuild. the wrapper script for
# eduke32 looks here for mods, and symlinks them into the user's
# ~/.eduke32/ so the game can find them.
EDUKEDIR=/usr/share/games/eduke32

# we don't even need a $TMP/$PRGNAM-$VERSION, just extract
# straight into $PKG
rm -rf $PKG/$EDUKEDIR
mkdir -p $TMP $PKG/$EDUKEDIR $OUTPUT
cd $PKG/$EDUKEDIR
unzip $CWD/$ZIPFILE "$DIRNAME/*"
find $DIRNAME -type f -print0 | xargs -0 chmod 644
find $DIRNAME -type d -print0 | xargs -0 chmod 755

# don't ship an empty texture cache
rm -f $DIRNAME/textures $DIRNAME/textures.cache

# upstream has no docs, we'll include our own README, which tells
# the user how to run the game.
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/README > $PKG/usr/doc/$PRGNAM-$VERSION/README
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz}
